const regs = {
    email: /^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/,
    phone: /^1[3-9]\d{9}$/,
    password: /^(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z\d]{8,18}$/,
    number: /^\d+$/,
}

const verify = (rule, value, reg, callback) => {
    try {
        if (value) {
            if (reg.test(value)) {
                callback()
            } else {
                callback(new Error(rule.message))
            }
        } else {
            callback();
        }
    } catch (error) {
        callback(new Error('验证出错'));
    }

}

export default {
    email: (rule, value, callback) => {
        return verify(rule, value, regs.email, callback)
    },
    number: (rule, value, callback) => {
        return verify(rule, value, regs.number, callback)
    },
    password: (rule, value, callback) => {
        return verify(rule, value, regs.password, callback)
    },

}